#pragma once
#include <atomic>
#include <map>
#include <windows.h>
#include <chrono>
#include <string>
#include "easylogging++.h"
#include "JsonUtil.h"
#include <filesystem>
#include <mutex>
#include <condition_variable>


class GlobalConstant {
public:
	std::string uuid = "";
	std::string custom = "fast";
	bool qr_text = false;
	bool exit = false;
	int open = 0;
	int fire_model = 0;
	int is_complement = 1;
	double full_magnification = 1.0;
	double low_magnification = 1.5;
	double stand_magnification = 1.0;
	double squat_magnification = 1.5;
	int gun_setting_select_key = VK_F1;
	std::string gun_setting_select_name = "M416";
	int gun_json_refresh = 0;
	int posture = 0;
	long long last_refresh_time = 0;
	std::vector<std::string> guns_images;
    std::map<DWORD, std::atomic<bool>> WatchedKeysState;
	std::map<int, std::string> KeyGunMap;
	std::map<std::string, Gun> gunMap;
	void set_gun_setting_select(const int gun_setting_select);
	void set_open(const int open);
	void set_posture(const int posture);
	void set_fire_model(const int gun_setting_select);
	void set_is_complement(const int is_complement);
	int loadSettings();
	void re_computeMovements();
	void exited();
};
extern GlobalConstant global_constant;

class GlobalFunc {
public:
	std::mutex mtx;
	std::condition_variable cv;
	bool ready = false;
	void park();
	void unpark();

	std::mutex mtxDraw;
	std::condition_variable cvDraw;
	bool readyDraw = false;
	void parkDraw();
	void unparkDraw();

	void delay(int timeout_ms);
};
extern GlobalFunc global_func;